var app = getApp();
const requireHttps = app.globalData.requireHttps //获取require域名
Page({
  data: {
    propertyName: '',
    propertyPhone: '',
    propertyList: [],
    auditStatus: ''
  },
  onLoad: function() {
    let _this = this;
    _this.successAudit()
    // console.log(app.globalData.auditStatus)
    _this.setData({
      auditStatus: app.globalData.auditStatus
    })
  },
  onShow:function() {
    let _this = this;
    _this.successAudit()
    // console.log(app.globalData.auditStatus)
    _this.setData({
      auditStatus: app.globalData.auditStatus
    })
  },
  propertyName: function(e) {
    let _this = this;
    _this.data.propertyName = e.detail.value
  },
  propertyPhone: function(e) {
    let _this = this;
    _this.data.propertyPhone = e.detail.value
  },
  goInAudit: function() {
    let _this = this;
    if (_this.data.propertyName == '' || _this.data.propertyPhone == '') {
      wx.showModal({
        title: '提示',
        content: '物业名称或联系电话不能为空',
        success: res => {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else if (_this.data.propertyPhone.length != 11) {
      wx.showModal({
        title: '提示',
        content: '请输入正确的联系电话',
        success: res => {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.request({
        url: '' + requireHttps + '/api/member/submitPropertyAudit',
        data: {
          property: _this.data.propertyName,
          phone: _this.data.propertyPhone,
          token: app.globalData.token
        },
        method: 'post',
        success: res => {
          console.log(res);
          wx.showToast({
            title: '提交成功！',
            success: res => {
              // wx.navigateTo({
              //   url: '/pages/inAudit/inAudit',
              // })
            }
          })
          
        }
      })
    }
  },
  successAudit: function () {
    let _this = this
    wx.request({
      url: '' + requireHttps + '/api/member/getPropertyInfo',
      data: {
        token: app.globalData.token
      },
      method: 'post',
      success: res => {
        // console.log(res)
        _this.setData({
          // propertyList: res.data.data
          propertyName: res.data.data.g_property,
          propertyPark: res.data.data.usable_parking,
        })
      },
      fail: error => {
        console.log(error)
      }
    })
  }
})